<?php
namespace Swiftx\Bundle\WeChat\Model\Seller;
use Swiftx\Bundle\WeChat\Interfaces\Common\EntityModel;

/**
 * 公司模型类
 */
class Company extends EntityModel {

    /**
     * 企业名称
     * @orm constraint unique
     * @orm constraint no-null
     * @orm type varchar(100)
     * @orm column Name
     */
    protected $name;

    /**
     * 邮箱地址
     * @var string
     * @orm constraint unique
     * @orm constraint no-null
     * @orm type varchar(100)
     * @orm column Username
     */
    protected $email;

    /**
     * 登陆密码
     * @var string
     * @orm constraint no-null
     * @orm type char(32)
     * @orm column Password
     */
    protected $password;

    /**
     * 公司LOGO
     * @var string
     * @orm type varchar(100)
     * @orm column Logo
     */
    protected $logo;

    /**
     * 默认相册
     * @var string
     * @orm constraint no-null
     * @orm type varchar(36)
     * @orm column DefaultAlbum
     */
    protected $defaultAlbum;

    /**
     * 店铺名称
     * @var string
     * @orm constraint no-null
     * @orm type varchar(100)
     * @orm column Title
     */
    protected $title;

    /**
     * 店铺名称
     * @var string
     * @orm constraint no-null
     * @orm type varchar(255)
     * @orm column Introduce
     */
    protected $introduce;


    /**
     * 读取企业名称
     * @return string
     */
    public function getName():string {
        return $this->name;
    }

    /**
     * 设置企业名称
     * @param string $value
     */
    public function setName(string $value){
        $this->name = $value;
    }

    /**
     * 设置企业游戏
     * @param string $value
     */
    public function setEmail(string $value){
        $this->email = $value;
    }

    /**
     * 读取企业邮箱
     * @return string
     */
    public function getEmail():string {
        return $this->email;
    }

    /**
     * 设置密码
     * @param string $value
     */
    public function setPassword(string $value){
        $this->password = md5($value);
    }

    /**
     * 校验密码
     * @param string $value
     * @return bool
     */
    public function checkPassword(string $value):bool {
        return $this->password == md5($value);
    }

    /**
     * 获取所有相册
     * @return Album[]
     */
    public function getAlbums():array {
        $query = $this->entityManager->query(Album::class, 'EqualByCompany');
        $query->bind('company', $this->getID());
        return $query->list();
    }

    /**
     * 读取标题
     * @return string
     */
    public function getTitle(){
        return $this->title;
    }

    /**
     * 设置标题
     * @param string $value
     */
    public function setTitle(string $value){
        $this->title = $value;
    }

    /**
     * 设置默认相册
     * @param string $id
     */
    public function setDefaultAlbum(string $id){
        $this->defaultAlbum = $id;
    }

    /**
     * 设置默认相册ID
     * @return string
     */
    public function getDefaultAlbumID():string {
        return $this->defaultAlbum;
    }

    /**
     * 读取介绍
     * @return string
     */
    public function getIntroduce(){
        return $this->introduce;
    }

    /**
     * 设置介绍
     * @param string $value
     */
    public function setIntroduce(string $value){
        $this->introduce = $value;
    }

    /**
     * 对象调试输出
     * @return mixed
     */
    public function __debugInfo(){
        $result['id'] = $this->id;
        $result['name'] = $this->name;
        $result['email'] = $this->email;
        $result['password'] = $this->password;
        $result['logo'] = $this->logo;
        $result['defaultAlbum'] = $this->defaultAlbum;
        $result['title'] = $this->title;
        $result['introduce'] = $this->introduce;
        return $result;
    }

}